/*
 * @lc app=leetcode.cn id=763 lang=swift
 *
 * [763] 划分字母区间
 */

// @lc code=start
class Solution {
    func partitionLabels(_ s: String) -> [Int] {
        var lastPoint: [Character: Int] = [:]

        var i = 0
        for c in s {
            lastPoint[c] = i
            i += 1
        }

        var result: [Int] = []
        var start = 0, end = 0
        i = 0
        for c in s {
            let lp = lastPoint[c]!
            end = max(end, lp)
            if i == end {
                result.append(end-start+1)
                start = end+1
            }
            i += 1
        }

        return result
    }
}
// @lc code=end

